package com.company;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class NGuessNumberTest {
    @org.junit.Test
    public void main(){

    }

    @Test
    public void generateAnswerTest(){
        int number = 4;
        NGuessNumber nGuessNumber = new NGuessNumber();
        assertEquals(number,nGuessNumber.generateAnswer().length);
        System.out.println("答案数字数量为4");

        int num [] = nGuessNumber.generateAnswer();
        boolean flag_1 = false;
        boolean flag_2 = false;

        for (int i=0; i<number; i++){
            if(num[i]>=0&&num[i]<=9){
                flag_1=true;
            }else{
                flag_1=false;
            }
            for (int j=0; j<=i; j++){
                if(i!=j) {
                    if (num[i] == num[j]) {
                        flag_2 = false;
                    } else {
                        flag_2 = true;
                    }
                }
            }
    }
        assertEquals(true,flag_2);
        System.out.println("其中无重复数字");

        assertEquals(true,flag_1);
        System.out.println("数字都在0-9之间");
    }

    @Test
    public void getPlayerInputTest(){
        int number= 4;
        NGuessNumber nGuessNumber = new NGuessNumber();
        assertEquals(number,nGuessNumber.generateAnswer().length);
        System.out.println("玩家输入数字数量为4");
    }

    @Test
    public  void compareGuessAnswerTest() {
        NGuessNumber nGuessNumber = new NGuessNumber();
        int[] numberArray = nGuessNumber.generateAnswer();
        int[] guessLArray = nGuessNumber.guessArray;
        int a_num = 0;
        int b_num = 0;
        for (int i = 0; i < numberArray.length; i++) {
            for (int j = 0; j < guessLArray.length; j++) {
                if (i == j) {
                    if (numberArray[i] == guessLArray[j]) {
                        a_num++;
                    }
                } else {
                    if (numberArray[i] == guessLArray[j]) {
                        b_num++;
                    }
                }
            }
        }
        String tiShi = a_num+"A"+b_num+"B\nA是位置和数字都猜对了，B是数字对位置错";

        assertEquals(tiShi,nGuessNumber.compareGuessAnswer());

        System.out.println("compareGuessAnswer测试通过");
    }

    @Test
    public void isWinTest(){
        NGuessNumber nGuessNumber = new NGuessNumber();
        boolean flag = false;

        if (nGuessNumber.a_num==4){
            flag=true;
            assertEquals(flag,nGuessNumber.isWin());
            System.out.println("true通过");
        }else {
            flag=false;
            assertEquals(flag,nGuessNumber.isWin());
            System.out.println("false通过");
        }
    }
}
